package com.robot.util;

import com.robot.model.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * User: li
 * Date: 2019/6/30
 * Time: 14:01
 * PROJECT：robot
 * PACKAGE: com.robot
 *
 * @author:55324936@qq.com To change this template use File | Settings | File Templates.
 */
public class SessionUtil {
    /**
     * 获取登录的用户信息
     * **/
    public static User getSessionUser(){
        return (User)getSession().getAttribute("user");
    }
    /**
     * 获取session信息
     * **/
    public static HttpSession getSession(){
        return getRequest().getSession(false);
    }
    /**
     * 获取request信息
     * **/
    public static HttpServletRequest getRequest(){
        ServletRequestAttributes requestAttributes =(ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        return requestAttributes ==null? null:requestAttributes.getRequest();
    }
}
